<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2019 广东卓锐软件有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------

// 为方便系统核心升级，二次开发中需要用到的公共函数请写在这个文件，不要去修改common.php文件

if (!function_exists("dd")) {
	function dd($data,$flag = true){
		dump($data);
		$flag && die;
	}
}








if (!function_exists('curl_send')) {
    /**
    * [发送curl请求]
    * @author MrGuo
    * @date   2020-12-19
    * @param  string $url    [请求链接]
    * @param  array  $data   [参数]
    * @param  array  $header [请求Header]
    * @param  array  $isPost [默认为post, false为GET]
    * @return [type]         [false表示失败]
    */
    function curl_send(string $url = '', $data = [], array $header = [], bool $isPost = true) {
        $ch = curl_init();
        // $header=[
        //      'Content-Type:'.'application/x-www-form-urlencoded; charset=UTF-8'
        // ];
        //  curl_setopt($ch, CURLOPT_SSLVERSION, 1);//检验SSL
        // if (defined('CURL_SSLVERSION_TLSv1')) {
        //  curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
        // }
        if (!empty($header)) {
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
            curl_setopt($ch, CURLOPT_HEADER, 0); //返回response头部信息
        }
        if ($isPost) {
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, gettype($data) == 'string' ? $data : http_build_query($data));
        } else {
            if (!empty($data)) {
                $url .= "?" . (gettype($data) == 'string' ? $data : http_build_query($data));
            }
        }
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        $rs = curl_exec($ch);
        if (curl_errno($ch)) {
          //出错则显示错误信息
          //var_dump( curl_error($ch) );
          return false;
        } else {
            curl_close($ch);
            //默认了进行了json转换
            $arr = json_decode($rs, true);
            if ($arr) {
                return $arr;
            }
            return $rs;
        }
    }
}